package com.hfi.restful.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2019/7/31
 */
@Configuration
public class MyFilterConfig {

    @Bean
    public FilterRegistrationBean timeFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        TimeFilter timeFilter = new TimeFilter();
        filterRegistrationBean.setFilter(timeFilter);

        List<String> urls = new ArrayList<>();
        // 可以设置路径 只有在满足路径下才会起作用
        // 设置为全部拦截 /*
        urls.add("/user/2");
        filterRegistrationBean.setUrlPatterns(urls);
        return filterRegistrationBean;
    }
}
